using Newtonsoft.Json.Linq;
using Org.BouncyCastle.Asn1.Ocsp;
using QQZiFramework;
using QQZiFramework.Membership;
using RabbitMQ.Client;
using System.Collections.Specialized;
using System.Web;

namespace TestProject1
{
    [TestClass]
    public class TestHttp
    {
        DBContext Context;
        public TestHttp()
        {
            var _OEMProgram = new OEMProgram("JPAAS");
            _OEMProgram.Run(null);
            Context = _OEMProgram.CreateDBContext();
        }    
 
        [TestMethod]
        public void TestDelete()
        {

            NameValueCollection headers = new NameValueCollection();
            headers.Add("Authorization", "Bearer aff6ade022994a299fea3b43bad4f3a2");
            headers.Add("Tenant-Id", "199");
            var res= Context.NewHttpUtility().DoDelete("http://ingress.ngrok.max913.com:8081/admin-api/bpm/process-instance/cancel", System.Text.Encoding.UTF8.GetBytes("{\"id\":\"9586d60a-1ca4-11ee-bd3c-22c19b98265a\",\"reason\":\"test\"}"), "application/json", headers );
            Assert.IsNotNull(res);
            var jtoken = JToken.Parse(res);
            Assert.IsNotNull(jtoken["code"] );
        }

        [TestMethod]
        public void TestGet()
        {
            var tokenKey = "12342134";
            var headers = new NameValueCollection();
            if (tokenKey != null)
            {
                string time = QQZiFramework.Utility.GetIntFromTime().ToString();
                var md5 = QQZiFramework.Utility.EncryptMD5(tokenKey + time).ToLower();
                headers.Add("token", md5);
                headers.Add("time", time);
            }
            string json = Context.NewHttpUtility(120).DoGet("http://localhost:5100/jpaas/test/testMqtt", null, false, null, headers, null);
            Console.WriteLine("result:"+json);
        }



    }
}